<html>

<head>

<?php

include "../includes/constants.php";
include "../includes/db_schema.php";
$DefaultDB = $db_name;			// Default DB to access
$DefaultTable = "spells_new";	// Default Table to access

if (!isset($_GET[Table]) || $_GET[Table] == "") {
	if (isset($_POST[Table]) && $_POST[Table] != "") {$_GET[Table] = $_POST[Table];}
	else {$_GET[Table] = $DefaultTable;};
};

?>

</head>

<body>

<?php

if ($_POST) {
	$query = "ALTER TABLE $_POST[Table] CHANGE $_POST[ColNameOld] $_POST[ColNameNew] $_POST[DataType] $_POST[NotNull] ";
	echo $query;
	if (@mysql_query($query)) {echo "Update Successful!";}
	else {echo "Update Failed!";};
};

?>

<form method="POST" action="">
	Database: <input type="text" size="" name="DB" value=""><br>
	Table Name: <input type="text" size="13" name="Table" value="<?php echo $_GET[Table];?>">
		<button onclick="location.href='?Table=' + Table.value">Load</button><br>
	Old Column Name: <select name="ColNameOld">
		<option></option>
<?php

CreateTableSchema($_GET[Table],$db_name);

foreach($Schema[$_GET[Table]] as $Key => $Value) {
	echo "\t\t<option value=\"" . $Value[COLUMN_NAME] . "\"";
	if ($_POST[ColNameNew] == $Value[COLUMN_NAME]) echo " selected";
	echo ">" . $Value[ORDINAL_POSITION] . ". " . $Value[COLUMN_NAME] . "</option>\n";
};

?>
	</select><br>
	New Column Name: <input type="text" size="" name="ColNameNew" value=""><br>
	<input type="radio" name="DataType" value="INTEGER"<?php if($_POST[DataType] == "INTEGER") echo " checked";?>>Integer</input>
	<input type="radio" name="DataType" value="VARCHAR"<?php if($_POST[DataType] == "VARCHAR") echo " checked";?>>VarChar</input><br>
	<input type="checkbox" name="NotNull" value="NOT NULL"<?php if($_POST[NotNull] == "NOT NULL") echo " checked";?>>Not Null</input><br>
	<button type="submit">Update</button> <button type="reset">Reset</button><br>
	<a href="<?php echo $_SERVER[PHP_SELF];?>">Start Over</a>
</form>

<?php

/*
echo "<pre>\n";
print_r($Schema);
echo "</pre>\n";
*/

?>

</body>

</html>